<template>
 <div id="signin">
    <div class="logo">
      <img alt="logo" src="../assets/logo.png">
    </div>
    <div class="signin">
      <el-form :model="form" :rules="rules" ref="form" size="mini">
        <el-form-item prop="account">
          <el-input v-model="form.account" placeholder="Please 输入 Your Account！"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="form.password" placeholder="Please 输入 Your Password！"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="signIn('form')">SignIn</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        account: "",
        password: ""
      },
      rules: {
        account: [
          { required: true, message: '请输入通行证', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请输入通行证密码', trigger: 'blur' },
        ],
      }
    }
  },
  methods: {
    signIn(formName) {
      let _self = this;
      _self.$refs[formName].validate((valid) => {
        if (valid) {
            _self.axios.post(api.signin, _self.form).then((resp) => {
              if(200 == resp.data.code) {
                _self.$router.push(_self.$route.query.redirect)
                _self.$message.success(resp.data.msg)
              } else {
                _self.$message.warning(resp.data.msg)
              }
            },(resp) => {
              _self.$message.error("Internal Server Error")
            })
        } else {
          return false;
        }
      });
    },
  },
  mountedt() {
    this.axios.get(api.whoami).then(resp => {
      console.log(resp.data);
    })
  }
}
</script>
<style scoped>
#signin {
  text-align: center;
  color: #2c3e50;
  background-color: #C0C4CC;
  height: 100%;
}

.signin {
  margin-left: 50%;
  transform: translateX(-50%) translateY(60px);
  width: 380px;
}
.logo {
  transform: translateY(60px);
}

</style>
